package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

        Person p1 = new Person();
        System.out.println(p1);

        Person p2= new Person("李四",22);
        System.out.println(p2);

        //1获取类对象
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class,int.class);
        Object obj = c.newInstance("王五",20);
        System.out.println(obj);


    }
}
